<?php
$static = Yii::$app->homeUrl;

$base = Yii::$app->basePath;
?>
<!DOCTYPE html>
<html lang="zh">
    <head>
        <meta charset="utf-8"/>
        <meta content="ie=edge" http-equiv="X-UA-Compatible"/>
        <title>
            赚钱
        </title>
        <link href="<?php echo $static; ?>css/common/base.css" rel="stylesheet">
        <link href="<?php echo $static; ?>css/common/common.css" rel="stylesheet">
        <link href="<?php echo $static; ?>css/common/bootstrap.min.css" rel="stylesheet">
        <link href="<?php echo $static; ?>css/make.css" rel="stylesheet">
        <script src="<?php echo $static; ?>js/jquery-2.1.1.min.js" type="text/javascript"></script>
        <script src="<?php echo $static; ?>js/bootstrap.min.js" type="text/javascript"></script>
        <script src="<?php echo $static; ?>js/ajaxrequest.js"></script>
        <script src="<?php echo $static; ?>js/ajaxfileupload.js"></script>
    </head>
    <body>
        <div class="new_money">
            <h4>
                <?php if($data && isset($data['id'])):?>
                    编辑任务
                <?php else:?>
                    新建任务
                <?php endif;?>
            </h4>
            <ul class="money_ul">
                <p class="P_select">
                    任务类型
                    <?php if(empty($data)):?>
                        <select id="select_id">
                            <?php foreach ($typeArr as $type): ?>
                                <option value="<?php echo $type['id']; ?>"><?php echo $type['name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                        <p>
                            <ul class="money_ulTow" id="div_center">

                            </ul>
                        </p>
                    <?php else:?>
                        <select id="select_id">
                            <?php foreach ($typeArr as $type): ?>
                                <option value="<?php echo $type['id']; ?>" <?php echo $data['task_type'] == $type['id'] ? 'selected="selected"' : '';?>><?php echo $type['name']; ?></option>
                            <?php endforeach; ?>
                        </select>
                        <p>
                            <ul class="money_ulTow" id="div_center">
                                <div class="money_ulDiv_one">
                                    <ul>
                                        <li>
                                            任务标题
                                            <input class="form-control" id="title" placeholder="请输入" type="text" value="<?php echo $data['task_title'];?>">
                                        </li>
                                        <li>
                                            任务副标题
                                            <input class="form-control" id="sub_title" placeholder="请输入" type="text" value="<?php echo $data['sub_title'];?>">
                                        </li>
                                        <?php if(in_array($data['task_type'],[3,4,8,7,6,9])):?>
                                            <?php if(in_array($data['task_type'],[3,4,6,9])):?>
                                                <li>
                                                    任务外链
                                                    <input class="form-control" id="link" placeholder="请输入分享外链地址" type="text" value="<?php echo $data['link'];?>">
                                                </li>
                                            <?php elseif(in_array($data['task_type'],[8])):?>
                                                <li class="jieru_Li">
                                                    接入方式
                                                    <p class="money_ulDiv_one_P">
                                                        <span class="<?php echo $data['connect_type'] == '3' ? 'one_span' : '';?> wl">需说明页跳转</span>
                                                        <span class="<?php echo $data['connect_type'] == '1' ? 'one_span' : '';?> wl">直接外链跳转</span>
                                                        <span class="<?php echo $data['connect_type'] == '2' ? 'one_span' : '';?> wj">文件上传</span>
                                                    </p>
                                                    <input type="text" class="form-control jieru_Li_input" id="link" placeholder="请输入分享外链地址" value="<?php echo $data['connect_type'] != '2' ? $data['link'] : '';?>" <?php echo $data['connect_type'] == '2' ? 'style="display: none;"' : '';?>>

                                                    <input type="text" class="form-control  but_add_MP3_common" placeholder="MP3" <?php echo $data['connect_type'] != '2' ? 'style="display: none;"' : 'style="display: block;" value="'. $data['short_name'] .'"';?>>
                                                    <input id='upload_MP3' class="but_add_MP3"  name='UploadForm[file]' type="file" accept="audio/*" style="display: none;"> 
                                                    <input type="hidden" id="audio" value="<?php echo $data['connect_type'] == '2' ? $data['link'] : '';?>">
                                                    <button type="button" class="btn btn-primary add_MP3" <?php echo $data['connect_type'] != '2' ? 'style="display: none;"' : '';?>>点击上传</button>
                                                </li>
                                            <?php elseif(in_array($data['task_type'],[7])):?>
                                                <li class="jieru_Li">
                                                    接入方式
                                                    <p class="money_ulDiv_SP_P">
                                                        <span class="<?php echo $data['connect_type'] == '1' ? 'one_span' : '';?> wl">外链</span>
                                                        <span class="<?php echo $data['connect_type'] == '2' ? 'one_span' : '';?> wj">文件上传</span>
                                                    </p>
                                                    <input type="text" class="form-control jieru_Li_input" id="link" placeholder="请输入分享外链地址" value="<?php echo $data['connect_type'] != '2' ? $data['link'] : '';?>" <?php echo $data['connect_type'] == '2' ? 'style="display: none;"' : '';?>>

                                                    <input type="text" class="form-control  but_add_MP3_common" placeholder="MP3" <?php echo $data['connect_type'] != '2' ? 'style="display: none;"' : 'style="display: block;" value="'. $data['short_name'] .'"';?>>

                                                    <input id='upload_video' class="but_add_MP3"  name='UploadForm[file]' type="file" accept="video/*"  style="display: none;"> 
                                                    <input type="hidden" id="video" value="<?php echo $data['connect_type'] == '2' ? $data['link'] : '';?>">
                                                    <button type="button" class="btn btn-primary add_video" <?php echo $data['connect_type'] != '2' ? 'style="display: none;"' : '';?>>点击上传</button>
                                                </li>
                                            <?php endif;?>
                                            <li>
                                                任务文案
                                            </li>
                                            <?php if(count($data['desc'])>=2):?>
                                                <?php $i = 1;?>
                                                <?php foreach($data['desc'] as $v):?>
                                                    <li class="<?php echo $i > 1 ? 'money_ulDiv_one_WaTow' : 'money_ulDiv_one_Wa';?>">
                                                        <textarea class="comment_Wa" cols="27" maxlength="200" name="task_desc[]" rows="1"><?php echo $v['task_desc'];?></textarea>
                                                    </li>
                                                    <li class="money_ulDiv_one_Inpu">
                                                        <input class="form-control" name="image_short[]" placeholder="" type="text" value="<?php echo explode('/',$v['img_url'])[count(explode('/',$v['img_url']))-1];?>">
                                                        <input accept="image/gif,image/jpeg,image/jpg,image/png,image/svg,image/bmp" name="UploadForm[file]" id="imput_image<?php echo $i;?>" class="but_file but_fileOne" type="file">
                                                        <input type="hidden" name="image[]" value="<?php echo $v['img_url'];?>">
                                                        <button class="btn btn-primary button_Oneadd add_one" type="button">
                                                            添加本地图片
                                                        </button>
                                                    </li>
                                                    <?php $i++;?>
                                                <?php endforeach;?>
                                            <?php elseif(count($data['desc'])>0):?>
                                                <?php $i = 1;?>
                                                <?php foreach($data['desc'] as $v):?>
                                                    <li class="<?php echo $i > 1 ? 'money_ulDiv_one_WaTow' : 'money_ulDiv_one_Wa';?>">
                                                        <textarea class="comment_Wa" cols="27" maxlength="200" name="task_desc[]" rows="1"><?php echo $v['task_desc'];?></textarea>
                                                    </li>
                                                    <li class="money_ulDiv_one_Inpu">
                                                        <input class="form-control" name="image_short[]" placeholder="" type="text" value="<?php echo explode('/',$v['img_url'])[count(explode('/',$v['img_url']))-1];?>">
                                                        <input accept="image/gif,image/jpeg,image/jpg,image/png,image/svg,image/bmp" name="UploadForm[file]" id="imput_image<?php echo $i;?>" class="but_file but_fileOne" type="file">
                                                        <input type="hidden" name="image[]" value="<?php echo $v['img_url'];?>">
                                                        <button class="btn btn-primary button_Oneadd add_one" type="button">
                                                            添加本地图片
                                                        </button>
                                                    </li>
                                                    <?php $i++;?>
                                                <?php endforeach;?>
                                                <li  class="money_ulDiv_one_WaTow">
                                                    <textarea rows="1" name="task_desc[]" cols="27" class="comment_Wa" maxlength="200"></textarea>											
                                                </li>

                                                <li class="money_ulDiv_one_Inpu">
                                                    <input class="form-control" name="image_short[]" placeholder="" type="text" value="">
                                                    <input accept="image/gif,image/jpeg,image/jpg,image/png,image/svg,image/bmp" name="UploadForm[file]" id="imput_image2" class="but_file but_fileTow" type="file">
                                                    <input type="hidden" name="image[]" value="">
                                                    <button class="btn btn-primary button_Oneadd add_Tow" type="button">
                                                        添加本地图片
                                                    </button>
                                                </li>
                                            <?php else:?>
                                                <li  class="money_ulDiv_one_Wa">
                                                    <textarea rows="1" name="task_desc[]" cols="27" class="comment_Wa" maxlength="200"></textarea>											
                                                </li>

                                                <li class="money_ulDiv_one_Inpu">
                                                    <input class="form-control" name="image_short[]" placeholder="" type="text" value="">
                                                    <input accept="image/gif,image/jpeg,image/jpg,image/png,image/svg,image/bmp" name="UploadForm[file]" id="imput_image1" class="but_file but_fileOne" type="file">
                                                    <input type="hidden" name="image[]" value="">
                                                    <button class="btn btn-primary button_Oneadd add_one" type="button">
                                                        添加本地图片
                                                    </button>
                                                </li>

                                                <li  class="money_ulDiv_one_WaTow">
                                                    <textarea rows="1" name="task_desc[]" cols="27" class="comment_Wa" maxlength="200"></textarea>											
                                                </li>

                                                <li class="money_ulDiv_one_Inpu">
                                                    <input class="form-control" name="image_short[]" placeholder="" type="text" value="">
                                                    <input accept="image/gif,image/jpeg,image/jpg,image/png,image/svg,image/bmp" name="UploadForm[file]" id="imput_image2" class="but_file but_fileTow" type="file">
                                                    <input type="hidden" name="image[]" value="">
                                                    <button class="btn btn-primary button_Oneadd add_Tow" type="button">
                                                        添加本地图片
                                                    </button>
                                                </li>
                                            <?php endif;?>
                                            <p class="li_P"></p>
                                            <li>
                                                <button class="btn btn-primary button_ADDIMG" type="button">
                                                    新增预定描述和图片
                                                </button>
                                            </li>
                                        <?php elseif($data['task_type'] == '5'):?>
                                            <li class="jieru_Li">
                                                接入方式
                                                <p class="money_ulDiv_SP_P">
                                                    <span class="<?php echo $data['connect_type'] == '1' ? 'one_span' : '';?> wl">外链</span>
                                                    <span class="<?php echo $data['connect_type'] == '2' ? 'one_span' : '';?> wj">文件上传</span>
                                                </p>
                                                <input type="text" class="form-control jieru_Li_input" id="link" placeholder="请输入分享外链地址" value="<?php echo $data['connect_type'] != '2' ? $data['link'] : '';?>" <?php echo $data['connect_type'] == '2' ? 'style="display: none;"' : '';?>>

                                                <input type="text" class="form-control  but_add_MP3_common" placeholder="MP3" <?php echo $data['connect_type'] != '2' ? 'style="display: none;"' : 'style="display: block;" value="'. $data['short_name'] .'"';?>>

                                                <input id='upload_video' class="but_add_MP3"  name='UploadForm[file]' type="file" accept="video/*"  style="display: none;"> 
                                                <input type="hidden" id="video" value="<?php echo $data['connect_type'] == '2' ? $data['link'] : '';?>">
                                                <button type="button" class="btn btn-primary add_video" <?php echo $data['connect_type'] != '2' ? 'style="display: none;"' : '';?>>点击上传</button>
                                            </li>
                                        <?php endif;?>
                                    </ul>
                                </div>
                                <div class="money_ulDiv_Tow">
                                    <ul>
                                        <li>
                                            单次奖励
                                            <?php if($data['task_type'] != '2'):?>
                                                <input class="form-control" id="single_reward" placeholder="请输入" type="text" value="<?php echo $data['single_reward'];?>">
                                            <?php else:?>
                                                <input class="form-control" id="single_reward" placeholder="请输入" type="text" value="10-40" disabled="disabled">
                                            <?php endif;?>
                                        <l>
                                            金币
                                        </l>
                                        </li>
                                        <li>
                                            实际单价
                                            <?php if($data['task_type'] != '2'):?>
                                                <input class="form-control" id="real_price" placeholder="请输入" type="text" value="<?php echo $data['real_price'];?>">
                                            <?php else:?>
                                                <input class="form-control" id="real_price" placeholder="请输入" type="text" value="0" disabled="disabled">
                                            <?php endif;?>
                                        <l>
                                            元
                                        </l>
                                        </li>
                                        <li>
                                            单用户限制次数
                                            <?php if($data['task_type'] != '2'):?>
                                                <input class="form-control" id="single_limit_count" placeholder="请输入" type="text" value="<?php echo $data['single_limit_count'];?>">
                                            <?php else:?>
                                                <input class="form-control" id="single_limit_count" placeholder="请输入" type="text" value="0" disabled="disabled">
                                            <?php endif;?>
                                        <l>
                                            次
                                        </l>
                                        </li>
                                        <li>
                                            任务限制总次数
                                            <input class="form-control" id="total_limit_count" placeholder="请输入" type="text" value="<?php echo $data['total_limit_count'];?>">
                                        <l>
                                            次
                                        </l>
                                        <?php if($data['task_type'] == '5'):?>
                                            <li class="SC_bf">
                                                强制播放时长
                                            <input type="text" class="form-control" id="force_play_time" placeholder="请输入" value="<?php echo $data['force_play_time'];?>"> <l>秒</l>														
                                            </li>
                                        <?php endif;?>
                                        </li>
                                        <li>
                                            当前完成状态
                                            <span class="money_ulDiv_Tow_span">
                                                <k>
                                                    <?php echo $data['finish_count'];?>
                                                </k>
                                                / 
                                                <?php if($data['total_limit_count'] == '0'):?>
                                                    不限
                                                <?php else:?>
                                                    <?php echo $data['total_limit_count'];?>
                                                <?php endif;?>
                                            </span>
                                        </li>
                                        <li>
                                            是否需要审核
                                            <p id="is_need_verify" class="money_ulDiv_Tow_p _SPan">
                                                <span <?php echo $data['is_need_verify'] == '1' ? 'class="one_span"' : '';?>>
                                                    是
                                                </span>
                                                <span <?php echo $data['is_need_verify'] == '0' ? 'class="one_span"' : '';?>>
                                                    否
                                                </span>
                                            </p>
                                        </li>
                                        <li>
                                            投放状态
                                            <p id="put_in_status" class="money_ulDiv_Tow_p _SPanS">
                                                <span <?php echo $data['put_in_status'] == '0' ? 'class="one_span"' : '';?>>
                                                    关闭
                                                </span>
                                                <span <?php echo $data['put_in_status'] == '1' ? 'class="one_span"' : '';?>>
                                                    开启
                                                </span>
                                            </p>
                                        </li>
                                        <li>
                                            任务备注
                                        </li>
                                        <li class="money_ulDiv_one_Wa money_ulDiv_Tow_Wa">
                                            <textarea class="comment_Wa comment_Wa_Tow" cols="27" maxlength="200" name="comments" id="remark" rows="1"><?php echo $data['remark'];?></textarea>
                                        </li>
                                    </ul>
                                </div>
                            </ul>
                        </p>
                    <?php endif;?>
                </p>
            </ul>
            <p class="lassLI">
                <button class="btn btn-primary tw_QDOK" type="button">
                    保存创建
                </button>
                <button class="btn btn-primary tw_QX" type="button">
                    取消
                </button>
            </p>
            <input type="hidden" id="task_id" value="<?php echo $data ? $data['id'] : ''?>">
        </div>
        <div class="bottom">
        </div>
    </body>
</html>
<script>
    var img_count = <?php echo $data && count($data['desc']) >= 2 ? count($data['desc']) : 2;?>;
    
    $(".tw_QDOK").click(function () {
        var type = $("#select_id").find("option:selected").text();
        var id = $("#task_id").val();
        var title = $("#title").val();
        var sub_title = $("#sub_title").val();
        var single_reward = $("#single_reward").val();
        var real_price = $("#real_price").val();
        var single_limit_count = $("#single_limit_count").val();
        var total_limit_count = $("#total_limit_count").val();
        var is_need_verify = 0;
        if($("#is_need_verify span").eq(0).hasClass("one_span")){
            is_need_verify = 1;
        }
        var put_in_status = 0;
        if($("#put_in_status span").eq(1).hasClass("one_span")){
            put_in_status = 1;
        }
        var remark = $("#remark").val();
        var link = '';
        var connect_type = 1;
        var force_play_time = 0;
        if(type == '分享享点app任务' || type == '分享' || type == '活动' || type == '图文'){
            link = $("#link").val();
        }else if(type == '试用'){
            if($(".money_ulDiv_one_P span").eq(2).hasClass("one_span")){
                connect_type = 2;
                link = $("#audio").val();
            }else if($(".money_ulDiv_one_P span").eq(0).hasClass("one_span")){
                connect_type = 3;
                link = $("#link").val();
            }else{
                link = $("#link").val();
            }
        }else if(type == '视频' || type == '下载'){
            if($(".money_ulDiv_SP_P span").eq(1).hasClass("one_span")){
                connect_type = 2;
                link = $("#video").val();
            }else{
                link = $("#link").val();
            }
            force_play_time = $("#force_play_time").val();
        }
        var task_desc = [];
//        var allow = 1;
        $("textarea[name='task_desc[]']").each(function(){
            var url = $(this).parent().next().find("input[name='image[]']").val();
            var desc = $(this).val();
//            if(desc == '' || url == ''){
//                alert("请检查必填项!");
//                allow = 2;
//                return false;
//            }
            if(desc != ''){
                var str_json = {'task_desc':desc,'img_url':url};
                task_desc.push(str_json);
            }
        });
//        if(allow == 2){
//            return;
//        }
        $.ajax({
            url:"/task/create",
            type:"post",
            dataType:"json",
            data:{type:type,title:title,sub_title:sub_title,single_reward:single_reward,real_price:real_price,
                  single_limit_count:single_limit_count,total_limit_count:total_limit_count,is_need_verify:is_need_verify,
                  put_in_status:put_in_status,remark:remark,task_desc:task_desc,link:link,connect_type:connect_type,
                  force_play_time:force_play_time,id:id
            },
            success:function(data){
                if(data.status == 0){
                    location.href="/task/task-list";
                }else{
                    alert(data.msg);
                }
            }
        });
        return;
    });
    
    $(".tw_QX").click(function () {
        location.href="/task/task-list";
    });

    /*动态加载*/

    function AJaxHtml(Url) {
        var ajaxobj = new AJAXRequest;
        ajaxobj.method = "GET";
        ajaxobj.url = Url
        ajaxobj.callback = function (xmlobj) {
            document.getElementById("div_center").innerHTML = ""
            document.getElementById("div_center").innerHTML = xmlobj.responseText;
            Active()
        }
        ajaxobj.send();
    }

    var Text = $("#select_id").find("option:selected").text();
    $("#select_id").change(function () {
        Text = $(this).find("option:selected").text()
        AJAXIF()
    });

    function AJAXIF() {
        if (Text == "有偿阅读任务") {
            AJaxHtml("../html/read.html")
        }else if (Text == "签到任务") {
            AJaxHtml("../html/sign_in.html")
        }else if (Text == "分享享点app任务") {
            AJaxHtml("../html/app_share.html")
        }else if (Text == "分享") {
            AJaxHtml("../html/share.html")
        } else if (Text == "活动") {
            AJaxHtml("../html/activity.html")
        } else if (Text == "试用") {
            AJaxHtml("../html/test.html")
        } else if (Text == "视频") {
            AJaxHtml("../html/video.html")
        } else if (Text == "图文") {
            AJaxHtml("../html/img_text.html")
        } else if (Text == "下载") {
            AJaxHtml("../html/down.html")
        } else {
            alert("错误，请刷新页面！")
            $("#div_center").html("")
        }
    }

    <?php if(empty($data)):?>
        AJAXIF()
    <?php else:?>
        Active()
    <?php endif;?>


    /*页面操作*/
    function Active() {

        $(".add_one,.add_Tow").click(function () {
            var IN_put = $(this).parent().find("input").eq(1)

//            IN_put.unbind("change", function () {
//                return false;
//            })
            IN_put.trigger('click')
        })
        
        $(".add_MP3").click(function () {
            var IN_put = $("#upload_MP3")
            IN_put.trigger('click')
        })
        
        $(".add_video").click(function () {
            var IN_put = $("#upload_video")
            IN_put.trigger('click')
        })
        
        $("#upload_MP3").on("change", function () {
            if ($(this).val().length > 0) {
                $.ajaxFileUpload
                (
                    {
                        url: '/server/upload-audio', //用于文件上传的服务器端请求地址
                        secureuri: false, //一般设置为false
                        fileElementId: 'upload_MP3', //文件上传空间的id属性  <input type="file" id="file" name="file" />
                        dataType: 'json', //返回值类型 一般设置为json
                        success: function (data, status)  //服务器成功响应处理函数
                        {
                            if (data.status == '0') {
                                $("#upload_MP3").prev().val(data.data.name);
                                $("#upload_MP3").next().val(data.data.url);
                            }else{
                                alert(data.msg);
                            }
                        },
                        error: function (data, status, e)//服务器响应失败处理函数
                        {
                            alert("系统繁忙请稍后再试");
                        }
                    }
                )
            } else {
                alert("请选择文件");
            }
            return false;
        })
        
        $("#upload_video").on("change", function () {
            if ($(this).val().length > 0) {
                $.ajaxFileUpload
                (
                    {
                        url: '/server/upload-video', //用于文件上传的服务器端请求地址
                        secureuri: false, //一般设置为false
                        fileElementId: 'upload_video', //文件上传空间的id属性  <input type="file" id="file" name="file" />
                        dataType: 'json', //返回值类型 一般设置为json
                        success: function (data, status)  //服务器成功响应处理函数
                        {
                            if (data.status == '0') {
                                $("#upload_video").prev().val(data.data.name);
                                $("#upload_video").next().val(data.data.url);
                            }else{
                                alert(data.msg);
                            }
                        },
                        error: function (data, status, e)//服务器响应失败处理函数
                        {
                            alert("系统繁忙请稍后再试");
                        }
                    }
                )
            } else {
                alert("请选择文件");
            }
            return false;
        })

        /*	$(".add_MP3").click(function(){
         $("#upload_MP3").unbind("change",function(){
         return false;
         })
         $('.but_add_MP3').click()
         })
         */

        function FOR(ThisClass) {
            for (var i = 0; i < ThisClass.length; i++) {
                ThisClass.eq(i).click(function () {
                    ThisClass.removeClass("one_span")
                    $(this).addClass("one_span")
                })
            }

        }

        FOR($("._SPan>span"))
        FOR($("._SPanS>span"))
        FOR($(".money_ulDiv_one_P>span"))
        FOR($(".money_ulDiv_SP_P>span"))


        $(".wl").click(function () {
            $(".add_MP3").hide()
            $(".add_video").hide();
            $(".but_add_MP3_common").hide()
            $(".jieru_Li_input").show()
        })

        $(".wj").click(function () {
            var type = $("#select_id").find("option:selected").text();
            if(type == '视频' || type == '下载'){
                $(".add_video").show()
            }else{
                $(".add_MP3").show()
            }
            $(".but_add_MP3_common").show()
            $(".jieru_Li_input").hide()
        })

        var Html = ""
        $(".button_ADDIMG").click(function () {
            img_count += 1;
            Html = "<li class='money_ulDiv_one_WaTow'><textarea rows='1' name='task_desc[]' cols='27' class='comment_Wa' maxlength='200'></textarea></li>" +
                    "<li class='money_ulDiv_one_Inpu'><input type='text' class='form-control' name='image_short[]' placeholder='' value=''>" +
                    "<input id='imput_image"+img_count+"' class='but_file but_fileTow' name='UploadForm[file]' type='file' accept='image/gif,image/jpeg,image/jpg,image/png,image/svg,image/bmp'>" +
                    "<input type='hidden' name='image[]' value=''>" +
                    "<button type='button' class='btn btn-primary button_Oneadd add_Tow'>" + "添加本地图片" + "</button></li>";
            $(".li_P").append(Html)

            $(".add_one,.add_Tow").click(function () {
                var IN_put = $(this).parent().find("input").eq(1)

//                IN_put.unbind("change", function () {
//                    return false;
//                })
                IN_put.trigger('click')
            })
            
            $(".but_file").on("change", function () {
                var id = $(this).attr('id');
                if ($(this).val().length > 0) {
                    $.ajaxFileUpload
                    (
                        {
                            url: '/server/upload-images', //用于文件上传的服务器端请求地址
                            secureuri: false, //一般设置为false
                            fileElementId: id, //文件上传空间的id属性  <input type="file" id="file" name="file" />
                            dataType: 'json', //返回值类型 一般设置为json
                            success: function (data, status)  //服务器成功响应处理函数
                            {
                                if (data.status == '0') {
                                    $("#"+id).prev().val(data.data.name);
                                    $("#"+id).next().val(data.data.url);
                                }else{
                                    alert(data.msg);
                                }
                            },
                            error: function (data, status, e)//服务器响应失败处理函数
                            {
                                alert("系统繁忙请稍后再试");
                            }
                        }
                    )
                    return false;
                } else {
                    alert("请选择图片");
                }
            })

        })
        
        $(".but_file").on("change", function () {
            var id = $(this).attr('id');
            if ($(this).val().length > 0) {
                $.ajaxFileUpload
                (
                    {
                        url: '/server/upload-images', //用于文件上传的服务器端请求地址
                        secureuri: false, //一般设置为false
                        fileElementId: id, //文件上传空间的id属性  <input type="file" id="file" name="file" />
                        dataType: 'json', //返回值类型 一般设置为json
                        success: function (data, status)  //服务器成功响应处理函数
                        {
                            if (data.status == '0') {
                                $("#"+id).prev().val(data.data.name);
                                $("#"+id).next().val(data.data.url);
                            }else{
                                alert(data.msg);
                            }
                        },
                        error: function (data, status, e)//服务器响应失败处理函数
                        {
                            alert("系统繁忙请稍后再试");
                        }
                    }
                )
                return false;
            } else {
                alert("请选择图片");
            }
        })

    }
</script>